<%@page contentType="text/html; charset=utf-8" %>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${ctx}/styles/aux_window.css" rel="stylesheet" type="text/css">
<title>Insert title here</title>
<script language="JavaScript" type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript">
	var developerIds = null;
	var designIds = null;
	var constructionIds = null;
	var supervisionIds = null;

	var developerSelectFrame = null;
	var designSelectFrame = null;
	var constructionSelectFrame = null;
	var supervisionSelectFrame = null;

	var isClose = null;

	//已选择IDS初始化标识,true表示已经初始化过，false表示没有初始化
	//因为在关闭页面时，需要判断developerIds...等是否改变
	var initSelectIdsStatus = false;

	/**
	*提交保存的数据
	*/
	function submitForm(closeFlag){
	    if(closeFlag == "isClose") isClose = "isClose";  //如果是点击的关闭按钮,则设置改标志,说明是点的关闭按钮。
	    if(closeFlag == "isSave") isClose = "isSave";  //如果是点击的保存按钮,则设置标识为保存,需要初始化已选择的ID值。
		var url = "${ctx}/house_projectAction.do?method=saveCoWorkerToProject";
		new Ajax.Request(url,
	                  {method: 'post', parameters: null, onComplete:function(){
	                  										<c:if test="${empty isArea}">
	                  											parent.windowOption.setButtonUsed();
	                  										</c:if>
	                  										<c:if test="${not empty isArea}">
																parent.areaObj.setSaveClick();
	                  										</c:if>
	                  										if(isClose == "isClose"){
	                  											parent.windowClose();
	                  											return ;
	                  										}
	                  										initSelectIds();
	                  							}
	                  }
	                  );
	}

	function allowClose(){
	   // return true;   //直接把关闭按钮 判断有数据修改的功能给屏蔽了。
		var temp = developerSelectFrame.getSelectedIds();
		var flag = (temp == developerIds);
		if(!flag) return false;

		temp = designSelectFrame.getSelectedIds();
		flag = (temp == designIds);
		if(!flag) return false;

		temp = constructionSelectFrame.getSelectedIds();
		flag = (temp == constructionIds);
		if(!flag) return false;

		temp = supervisionSelectFrame.getSelectedIds();
		flag = (temp == supervisionIds);
		if(!flag) return false;

		return true;
	}

	/**刷新frame***/
	function reloadFrame(coworkerType){
		if(_checkCoworkerType(coworkerType)){
			document.frames( coworkerType + "SelectFrame").location.reload();
		}
	}
	//检测参建单位标识字符串是否合法
	function _checkCoworkerType(coworkerType){
		if(coworkerType == null || coworkerType == "")
			return false;
		if(coworkerType != "developer" && coworkerType !="design" && coworkerType !="construction" && coworkerType !="supervision")
			return false;
		return true;
	}
	function init(){
		initFrame();  //初始化列表 iframe
	}
	//初始化列表
	function initFrame(){
		developerSelectFrame = window.frames("developerSelectFrame");
		designSelectFrame =  window.frames("designSelectFrame");
		constructionSelectFrame = window.frames("constructionSelectFrame");
		supervisionSelectFrame = window.frames("supervisionSelectFrame");
		//开发商
		var developerUrl = "${ctx}/house_projectAction.do?method=initCoWorkerSelectedList";
		developerSelectFrame.location.href = developerUrl + "&coWorkerType=developer";
		//设计单位
		designSelectFrame.location.href = developerUrl+ "&coWorkerType=design" ;
		//施工单位
		constructionSelectFrame.location.href = developerUrl+ "&coWorkerType=construction" ;
		//监理单位
		supervisionSelectFrame.location.href = developerUrl+ "&coWorkerType=supervision" ;
	}

	function initSelectIds(){
		//初始化已选择的值,由于iframe加载循序不一样，有些方法可能访问不到,只要该方法存在就执行  执行前判断就好了
		if(developerIds == null || isClose == "isSave") developerIds = developerSelectFrame.getSelectedIds();
		if(designIds == null  || isClose == "isSave") designIds = designSelectFrame.getSelectedIds();
		if(constructionIds == null || isClose == "isSave")constructionIds = constructionSelectFrame.getSelectedIds();
		if(supervisionIds == null || isClose == "isSave")supervisionIds = supervisionSelectFrame.getSelectedIds();
	}
</script>
</head>
<body onload="init();">
			  <div id="tab_subMenu5" style="height:355px;overflow:auto;">
                <table width="100%" height="360px" border="0" align="center" cellpadding="1" cellspacing="0">
                  <tr>
                    <td valign="top" ><table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" >
                        <tr>
                          <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color"  style="display:show">
                              <tr>
                                <td colspan="4" class="aux_titletable">开发商</td>
                              </tr>
                            </table>
                              <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tab_line">
                                <tr>
                                  <td valign="top">
                                  	<iframe id="developerSelectFrame" src="" width="100%" frameborder="0"></iframe>
                                  </td>
                                </tr>
                              </table>
                            <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color"  style="display:show">
                                <tr>
                                  <td colspan="4" class="aux_titletable">设计单位</td>
                                </tr>
                            </table>
                            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tab_line">
                                <tr>
                                  <td valign="top">
                                  	<iframe id="designSelectFrame" src="" width="100%" frameborder="0" ></iframe>
                                  </td>
                                </tr>
                            </table>
                            <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color"  style="display:show">
                                <tr>
                                  <td colspan="4" class="aux_titletable">施工单位</td>
                                </tr>
                            </table>
                            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tab_line">
                                <tr>
                                  <td valign="top">
										<iframe id="constructionSelectFrame" src="" width="100%" frameborder="0" ></iframe>
                                  </td>
                                </tr>
                            </table>
                            <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color"  style="display:show">
                                <tr>
                                  <td colspan="4" class="aux_titletable">监理单位</td>
                                </tr>
                            </table>
                            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tab_line">
                                <tr>
                                  <td valign="top">
									<iframe id="supervisionSelectFrame" src="" width="100%" frameborder="0"></iframe>
                                  </td>
                                </tr>
                            </table></td>
                        </tr>
                    </table></td>
                  </tr>
                </table>
		      </div>
</body>
</html>